package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.helper.UnionActivityGroupHelper;
import com.yanqu.road.logic.rank.RankListModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.commonactivity.CommonActivityProto;
import com.yanqu.road.pb.rank.YRankProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.rank.ActivityRankMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_ACTIVITY_RANK_LIST_TOP_THREE, desc = "个人活动积分排行榜前N,newRank才有用")
public class ActivityRankListTopThreeCmd extends AbstractCommand {

    private int activityId;
    private int conditionType;
    private int onlyTopNum = 0;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CommonActivityProto.CommonActivityRankListReqMsg reqMsg = CommonActivityProto.CommonActivityRankListReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionType = reqMsg.getRankType();
        if (reqMsg.hasOnlyTopNum()){
            onlyTopNum = reqMsg.getOnlyTopNum();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData(GamePlayer player) {
        CommonActivityProto.CommonActivityRankListRespMsg.Builder respMsg = CommonActivityProto.CommonActivityRankListRespMsg.newBuilder();
        respMsg.setMyRank(-1);
        ActivityInfo openActivityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (null != openActivityInfo) {
            boolean isCrossRank = ActivityHelper.conditionTypeIsCrossRank(conditionType);
            if(isCrossRank){//跨服活动
                /*RankProto.RankListMsg.Builder rankListMsg = CrossDataMgr.getCrossUserRankActivityRankMsg(activityId, conditionType);
                respMsg.setRankList(rankListMsg);
                respMsg.setMyRank(ActivityMgr.getMyCrossRank(player.getUserId(), rankListMsg));*/
                CommonActivityProto.CommonActivityRankListReqMsg.Builder msg = CommonActivityProto.CommonActivityRankListReqMsg.newBuilder();
                msg.setActivityId(activityId);
                msg.setRankType(conditionType);
                msg.setOnlyTopNum(onlyTopNum);
                player.sendPacket(Protocol.C2_CROSS_GET_USER_ACTIVITY_RANK, msg);
                return;
            }
        }
        player.sendPacket(Protocol.U_ACTIVITY_RANK_LIST, respMsg);
    }
}
